package org.jeecg.trace.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.trace.dto.FaultStatisticsDTO;
import org.jeecg.trace.service.FaultStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Description: qis_reinspect_cfg
 * @Author: LiCY
 * @Date:   2023-10-17
 * @Version: V1.0
 */
@Api(tags="qis_reinspect_cfg")
@RestController
@RequestMapping("/trace/faultStatistics")
@Slf4j
public class FaultStatisticsController {

    @Autowired
    private FaultStatisticsService faultStatisticsService;


    /**
     * 分页列表查询666
     *
     * @param param
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "qis_reinspect_cfg-分页列表查询")
    @ApiOperation(value="qis_reinspect_cfg-分页列表查询", notes="qis_reinspect_cfg-分页列表查询")
    @GetMapping(value = "/list")
    @DS("history")
    public Result<IPage<FaultStatisticsDTO>> queryPageList(@RequestParam Map<String, Object> param,
                                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                        HttpServletRequest req) {
        Page<FaultStatisticsDTO> page = new Page<FaultStatisticsDTO>(pageNo, pageSize);
        if (param.containsKey("line")){
            IPage<FaultStatisticsDTO> pageList = faultStatisticsService.pageList(page, param);
            return Result.OK(pageList);
        }else {
            return Result.error("");
        }
    }

    /**
     * 导出excel
     *
     * @param request
     */
    //@RequiresPermissions("org.jeecg.modules.demo:mes_lot_cfg:exportXls")
    @RequestMapping(value = "/exportXls")
    @DS("history")
    public ModelAndView exportXls(HttpServletRequest request, @RequestParam Map<String, Object> param) {
        return faultStatisticsService.exportXls(request, param, FaultStatisticsDTO.class, "不良录入统计");
    }

    /**
     * 导出excel2
     *
     * @param request
     * @param param
     */
    //@RequiresPermissions("org.jeecg.modules.demo:eqp_fault_history:exportXls")
    @GetMapping(value = "/exportXls2")
    @DS("history")
    public void exportXls2(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, Object> param) {
        faultStatisticsService.exportXsl2(request,response,param);
    }


    /**
     * 分页列表查询666
     *
     * @param cfgId
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "qis_reinspect_cfg-分页列表查询")
    @ApiOperation(value="qis_reinspect_cfg-分页列表查询", notes="qis_reinspect_cfg-分页列表查询")
    @GetMapping(value = "/unitsnList")
    @DS("history")
    public Result<IPage<FaultStatisticsDTO>> unitsnList(@RequestParam String cfgId,
                                                           @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                           HttpServletRequest req) {
        Page<FaultStatisticsDTO> page = new Page<FaultStatisticsDTO>(pageNo, pageSize);
//        IPage<FaultStatisticsDTO> pageList = faultStatisticsService.unitsnList(page, cfgId);
        return Result.OK("pageList");
    }

}
